package com.jwt.demo.handler;

import com.jwt.demo.Result;
import com.jwt.demo.util.CustomException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 林武杰
 * @date 2021/10/12 15:45
 */
@ControllerAdvice
public class CustomExceptionHandler {

    @ResponseBody
    @ExceptionHandler(CustomException.class)
    public Result errHandler(HttpServletRequest request, Exception e){
        return Result.error(100,e.getMessage());
    }
}
